package com.lljin.study.orderserviceprovider.controller;

import com.lljin.study.client.OrderServiceFeignClient;
import com.lljin.study.dto.OrderDto;
import com.lljin.study.service.OrderService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.TimeUnit;

/**
 * @author lljin
 * @description TODO
 * @date 2020/7/13 22:36
 */
@RestController
@RefreshScope
public class OrderController implements OrderServiceFeignClient {

    private final OrderService orderService;
    @Value("${env}")
    private String env;

    public OrderController(OrderService orderService) {
        this.orderService = orderService;
    }

    @Override
    public String order(String id) {
        return "env:" + env + "  " + orderService.queryOrderById(id);
    }

    @Override
    public String testHystrix(int num) {
        if (num % 2 ==0){
            try {
                TimeUnit.SECONDS.sleep(3);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        return "正常返回";
    }

    @Override
    public String insert(OrderDto orderDto) {
        try {
            TimeUnit.SECONDS.sleep(3);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return "success insert "+ orderDto;
    }
}
